home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 9 / Night Owl CD-ROM (NOPV9) (Night Owl Publisher) (1993).ISO / 009a / snpd0493.zip / ISCONS.C < prev    next >
C/C++ Source or Header  |  1993-04-05  |  840b  |  40 lines

  1. /*
  2. **  iscons()
  3. **
  4. **  A function to determine if a specified stream refers to the console.
  5. **
  6. **  Original Copyright 1988-1991 by Bob Stout as part of
  7. **  the MicroFirm Function Library (MFL)
  8. **
  9. **  This subset version is hereby donated to the public domain.
  10. */
  11.  
  12. #include <stdio.h>
  13. #include <dos.h>
  14.  
  15. #define BOOL(x) (!(!(x)))
  16.  
  17. int iscons(FILE *fp)
  18. {
  19.       union REGS regs;
  20.  
  21.       regs.x.ax = 0x4400;
  22.       regs.x.bx = (unsigned)fileno(fp);
  23.       intdos(®s, ®s);
  24.       if (0 == (regs.x.ax & 0x80))
  25.             return 0;
  26.       return BOOL(regs.x.ax & 0x13);
  27. }
  28.  
  29. #ifdef TEST
  30.  
  31. int main(void)
  32. {
  33.       fprintf(stderr, "stdin is%s redirected\n",
  34.             iscons(stdin) ? " not" : "");
  35.       fprintf(stderr, "stdout is%s redirected\n",
  36.             iscons(stdout) ? " not" : "");
  37. }
  38.  
  39. #endif /* TEST */
  40.